package com.chushouya.controller.manager.admin;


import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.chushouya.manager.dto.admin.clerk.ClerkDetailDTO;
import com.chushouya.manager.dto.admin.clerk.ClerkListDTO;
import com.chushouya.manager.dto.admin.clerk.ClerkQuery;
import com.chushouya.manager.dto.admin.clerk.ClerkUpdateDTO;
import com.chushouya.manager.service.admin.ClerkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 业务员管理
 */
@RestController
@RequestMapping(ServiceType.PLATFORM + "/clerk")
@Api(tags = "platform业务员管理")
public class ClerkController {

    @Resource
    private ClerkService clerkService;

    @GetMapping("/page")
    @ApiOperation("查询业务员列表")
    public Response<PageResult<ClerkListDTO>> page(ClerkQuery query) {
        return Response.success(clerkService.selectPage(query));
    }

    @GetMapping("/detail")
    @ApiOperation("查询业务员详情")
    public Response<ClerkDetailDTO> detail(Long id) {
        return Response.success(clerkService.detail(id));
    }

    @PostMapping("/update")
    @ApiOperation("编辑业务员")
    @Log(businessType = BusinessType.UPDATE)
    public Response<Void> update(@RequestBody @Valid ClerkUpdateDTO dto) {
        clerkService.update(dto);
        return Response.success();
    }

    @PostMapping("/audit")
    @ApiOperation("业务员审核")
    @Log(businessType = BusinessType.UPDATE)
    public Response<Void> audit(Long clerkId) {
        clerkService.audit(clerkId);
        return Response.success();
    }

    @PostMapping("/editStatus")
    @ApiOperation("业务员启用/禁用")
    @Log(businessType = BusinessType.UPDATE)
    public Response<Void> editStatus(Long clerkId, Integer status) {
        clerkService.editStatus(clerkId, status);
        return Response.success();
    }

    @PostMapping("/editWorkStatus")
    @ApiOperation("业务员工作状态:接单中/停止接单")
    @Log(businessType = BusinessType.UPDATE)
    public Response<Void> editWorkStatus(Long clerkId, Integer workStatus) {
        clerkService.editWorkStatus(clerkId, workStatus);
        return Response.success();
    }


    @PostMapping("/remove")
    @ApiOperation("删除业务员")
    @Log(businessType = BusinessType.DELETE)
    public Response<Void> remove(Long id) {
        clerkService.remove(id);
        return Response.success();
    }


}
